import { createRouter, createWebHistory,createWebHashHistory } from 'vue-router'
import Home from '../views/Home.vue'
import store from '../store/index.js' 


const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
 
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import( '../views/About.vue')
  },
  {
    path: '/searchview',
    name: 'Searchview',
    component: () => import( '../views/Search.vue')
  },
  {
    path: '/listviews',
    name: 'ListViews',
    component: () => import( '../views/ListViews.vue')
  },
  {
    path: '/login',
    name: 'Login',
    beforeEnter: (to, from, next) => {
      // ...
      console.log(store.state.user.islogin)
      if(!store.state.user.islogin) {
        next()
      }else {
        next('/me')
      }
    },
    component: () => import( '../views/login.vue')
  },{
    path: '/me',
    name: 'Me',
    beforeEnter: (to, from, next) => {
     
      
      if(store.state.user.islogin) {
        next()
      }
    },
    component: () => import( '../views/Me.vue')
  },
]

const router = createRouter({
  // history: createWebHistory(process.env.BASE_URL),
  history: createWebHashHistory(process.env.BASE_URL),
  routes
})

export default router
